package com.allwees.bs.c.module.payment.controller;


import com.allwees.bs.c.module.base.controller.BaseController;
import com.allwees.bs.c.module.order.dto.OrderDTO;
import com.allwees.bs.c.module.payment.req.PaymentCodReq;
import com.allwees.bs.c.module.payment.req.SmsCodeReq;
import com.allwees.bs.c.module.payment.service.ICodPaymentService;
import com.allwees.bs.core.modelbase.vo.R;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RestController;

/**
 * 货到付款相关
 */
@Slf4j
@RestController
public class CodPaymentController extends BaseController {

    @Autowired
    private ICodPaymentService codPaymentService;

    /**
     * checkout cod订单
     *
     * @param req
     * @return
     */
    @PostMapping("/api/v1/payment/check_cod")
    public R checkCod(@RequestBody PaymentCodReq req) {
        return R.ok(codPaymentService.checkCod(req));
    }

    /**
     * COD发送验证码
     * @param smsCodeReq
     * @return
     */
    @PostMapping("/api/v1/sms_code/send")
    public R sendSmsCode(@RequestBody SmsCodeReq smsCodeReq) {
        codPaymentService.sendSmsCode(smsCodeReq);
        return R.ok();
    }

    /**
     * 生成cod订单
     *
     * @param req
     * @return
     */
    @PostMapping("/api/v1/payment/cod")
    public R codOrder(@RequestBody PaymentCodReq req) {
        OrderDTO order = this.codPaymentService.codOrder(req);
        return R.ok(order);
    }
}
